layui.use(['form', 'jquery', 'layer'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery;


    var sex = $("#sex").val();
    if (sex != null && sex != '') {
        if (sex == 1) {
            $("#woman").prop('checked', true);
            $("#man").attr("disabled", "disabled");
            form.render();
        } else if (sex == 0) {
            $("#man").prop('checked', true);
            $("#woman").attr("disabled", "disabled");
            form.render();
        }
    }

    var name = $("#linkName").val()
    if (name != null && name != '') {
        $("#linkName").attr("disabled", "disabled")
        form.render();
    }

    form.on('submit(addOrUpdateLinkMan)', function (data) {
        var index = layer.msg("数据提交中，请稍后", {
            icon: 16,
            time: false,
            shade: 0.8
        })
        var formData = data.field;
        var id = $("[name='id']").val();
        var url = ctx + "/supplier/addLinkMan";
        if (id != null && id != '') {
            url = ctx + "/supplier/updateLinkMan";
        }
        $.ajax({
            type: "post",
            data: formData,
            url: url,
            success: function (data) {
                if (data.code == 200) {
                    layer.msg(data.msg, {icon: 6})
                    layer.closeAll("iframe");
                    parent.location.reload();
                } else {
                    layer.msg(data.msg)
                }
            },
            error: function (data) {
                layer.msg(data.msg)
            }
        })
        return false;

    })


})